package vip.ifmm.lehouse.email.service.strategy.impl;

import org.springframework.stereotype.Component;
import vip.ifmm.lehouse.common.enums.type.EmailMimeType;
import vip.ifmm.lehouse.common.message.EmailSenderMessage;
import vip.ifmm.lehouse.email.service.api.EmailSenderService;
import vip.ifmm.lehouse.email.service.strategy.EmailSenderStrategy;

import javax.annotation.Resource;

/**
 * HTML 类型邮件发送策略
 *
 * @author Fish
 * <p>Email: fishinlove@163.com</p>
 * <p>created by 2019/06/18 20:08:15</p>
 */
@Component
public class HtmlEmailSenderStrategy implements EmailSenderStrategy {

    // 邮件发送服务
    @Resource
    private EmailSenderService senderService = null;

    @Override
    public EmailMimeType type() {
        return EmailMimeType.HTML;
    }

    @Override
    public void sendEmail(EmailSenderMessage message) {
        if (type().equals(message.getEmailType())) {
            // 异步发送邮件
            senderService.sendHtmlEmailAsync(
                    message.getEmailReceivers(),
                    message.getEmailTopic(),
                    message.getEmailContent()
            );
        }
    }
}
